package com.geoboard.fragments;

import java.util.ArrayList;

import android.os.Bundle;
import android.support.v4.app.ListFragment;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.geoboard.ActivityInterface;
import com.geoboard.R;
import com.geoboard.entity.Post;
import com.geoboard.service.ListAdapterPosts;

public class PostsTextFrag extends ListFragment{
	
	/**** Members **************************************************/
	private String TAG = this.getClass().getSimpleName();

	/**** Android Callback Methods *********************************/
	
	//TODO refresh posts periodically
	@Override
	public void onCreate(Bundle savedInstanceState){
		super.onCreate(savedInstanceState);
		
		ArrayList<Post> posts = ((ActivityInterface)getActivity()).getMapFrag().getVisiblePosts();
		if(posts != null){
			Log.d(TAG, String.format("listing %d posts", posts.size()));
			this.setListAdapter(new ListAdapterPosts(posts, getActivity()));
		}
	}
	
	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState){
		return inflater.inflate(R.layout.frag_posts_text, container, false);		
	}
}
